home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8288 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: bubba.NMSU.Edu!usenet
  2. From: ghenniga@ampere.NMSU.Edu (Gary Hennigan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: system() & error detection
  5. Date: 27 Feb 1996 08:42:01 -0700
  6. Organization: New Mexico State University - Electromagnetics Group
  7. Sender: ghenniga@ampere.NMSU.Edu
  8. Message-ID: <rht4tsclqra.fsf@ampere.NMSU.Edu>
  9. References: <4gt24g$dba@ncar.ucar.edu>
  10. Reply-To: ghenniga@NMSU.Edu
  11. NNTP-Posting-Host: ampere.nmsu.edu
  12. In-reply-to: jadams@sage.cgd.ucar.edu's message of 26 Feb 1996 19:36:48 GMT
  13. X-Newsreader: Gnus v5.1
  14.  
  15. In an article jadams@sage.cgd.ucar.edu (James Adams) wrote:
  16. > I am attempting to use the system() call in order to have a
  17. >user-specified command execute in my program.
  18. >
  19. > I am wondering how I can check whether or not the command has
  20. >completed successfully ?  I don't want the program to continue if the
  21. >call I make from system() produces some sort of error.  I'd like to be
  22. >able to do something like the following:
  23. >
  24. > result = system(command);
  25. > if (result == ERROR)
  26. >   exit(0);
  27. >
  28. >Is there anyway to do this ?  Should I be using something other than
  29. >system() ?
  30.  
  31. You may want to read the man page on system(). According to mine the
  32. system() function returns -1 if it can't execute the requested string,
  33. or returns the exit status of the shell if the command can be
  34. executed. Since the exit status of the shell is the exit status of the
  35. last command executed by the shell you effectively get the exit status
  36. of the requested command. So, if the requested command exits with
  37. status 0 when successful, as they commonly do, you can test to see if
  38. the command executed without error.
  39.  
  40. Gary
  41. (ghenniga@NMSU.Edu)
  42.